package com.tudouji.project.bill.controller;

import java.util.List;

import com.tudouji.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.bill.domain.Whinfo;
import com.tudouji.project.bill.service.IWhinfoService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 库存信息Controller
 * 
 * @author tudouji
 * @date 2021-04-13
 */
@RestController
@RequestMapping("/bill/whinfo")
public class WhinfoController extends BaseController
{
    @Autowired
    private IWhinfoService whinfoService;

    /**
     * 查询库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('bill:whinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Whinfo whinfo)
    {
        startPage();
        List<Whinfo> list = whinfoService.selectWhinfoList(whinfo);
        return getDataTable(list);
    }

    /**
     * 导出库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('bill:whinfo:export')")
    @Log(title = "库存信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Whinfo whinfo)
    {
        String tuserId = SecurityUtils.getLoginUser().getUser().getTuserId();
        List<Whinfo> list = null;//出入库统计→使用全局和库房就可以
        try {
            list = whinfoService.findDetailPC(whinfo, tuserId,true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        ExcelUtil<Whinfo> util = new ExcelUtil<Whinfo>(Whinfo.class);
        return util.exportExcel(list, "whinfo");
    }

    /**
     * 获取库存信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('bill:whinfo:query')")
    @GetMapping(value = "/{autoid}")
    public AjaxResult getInfo(@PathVariable("autoid") Long autoid)
    {
        return AjaxResult.success(whinfoService.selectWhinfoById(autoid));
    }

    /**
     * 新增库存信息
     */
    @PreAuthorize("@ss.hasPermi('bill:whinfo:add')")
    @Log(title = "库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Whinfo whinfo)
    {
        return toAjax(whinfoService.insertWhinfo(whinfo));
    }

    /**
     * 修改库存信息
     */
    @PreAuthorize("@ss.hasPermi('bill:whinfo:edit')")
    @Log(title = "库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Whinfo whinfo)
    {
        return toAjax(whinfoService.updateWhinfo(whinfo));
    }

    /**
     * 删除库存信息
     */
    @PreAuthorize("@ss.hasPermi('bill:whinfo:remove')")
    @Log(title = "库存信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{autoids}")
    public AjaxResult remove(@PathVariable Long[] autoids)
    {
        return toAjax(whinfoService.deleteWhinfoByIds(autoids));
    }

    /**
     * @param
     * @return void
     * @throws
     * @Title: findDetailPC
     * @Description: PC 端查询出库信息
     * @author liukx
     */
    @RequestMapping("/findDetailPC")
    public TableDataInfo findDetailPC(Whinfo whinfo) {
        String tuserId = SecurityUtils.getLoginUser().getUser().getTuserId();
        List<Whinfo> list = null;
        try {
            list = whinfoService.findDetailPC(whinfo, tuserId,false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getDataTable(list);
    }
}
